<?php

use Biz\service\brand\BrandUserPenalty;
use Doraemon\tools\Log;

class SyncAction extends ActionPlugin
{
    const IS_TRACING = true;

    const _DATABASE_ = 'hhzhome_admin';

    const _TABLE_NAME = 'hhz_themis_log';

    const TYPE_ADD = "insert";

    const TYPE_UPDATE = "update";

    /**
     * @throws Exception
     */
    public function main()
    {
        Log::info('themis_log 获取数据', $this->messageBody);
        if ($this->messageBody['database'] != self::_DATABASE_) throw new \Exception('数据库错误');
        if ($this->messageBody['table'] != self::_TABLE_NAME) throw new \Exception('数据表错误');
        if (!in_array($this->messageBody['type'], [self::TYPE_UPDATE, self::TYPE_ADD])) throw new \Exception('不是新增操作');
        if (!$this->messageBody['data']) throw new \Exception('未接收到数据');
        BrandUserPenalty::syncSave($this->messageBody);
        $this->setSuccess();
    }
}